import isPng from "./isPng.js";

// is png
function isPngTest(){
    const buffer = new Uint8Array([0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x25]);

    let startTime = Date.now();
    let result
    for (let i = 0; i < 1000000; i++) {
        result = isPng(buffer)
    }
    let endTime = Date.now();

    if(result !== true){
        throw new Error('is-png-master_isPng_0100 Error')
    }
    print(`is-png-master_isPng_0100: ${endTime - startTime} ms`)
    
    // if(isPng(buffer)){
    //     print('The file is in PNG format');
    // }else{
    //     print('This file is not in PNG format')
    // }
}

// is not png
function isNotPng(){
    const buffer = new Uint8Array([0x88, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x25]);

    let startTime = Date.now();
    let result
    for (let i = 0; i < 1000000; i++) {
        result = isPng(buffer)
    }
    let endTime = Date.now();

    if(result !== false){
        throw new Error('is-png-master_isNotPng_0200 Error')
    }
    print(`is-png-master_isNotPng_0200: ${endTime - startTime} ms`)
    
    // if(isPng(buffer)){
    //     print('The file is in PNG format');
    // }else{
    //     print('This file is not in PNG format')
    // }
}


function Switch() {
    isPngTest()
    isNotPng()
}
Switch()

